home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / kgb104.zip / KGB.ASM < prev    next >
Assembly Source File  |  1992-04-16  |  13KB  |  633 lines

  1.         .8086
  2.         .model small
  3.         .stack 200h
  4.         .code
  5. ResBeg        label byte
  6. BuffPos        dw    0
  7. BuffSize    dw    100h
  8. Old21        dd    ?
  9. status        dd    ?
  10. Off        db    0
  11. path        db    'C:\HISTORY.DAT',0
  12.         db    112 dup (0)
  13. functions    db    3ch,3dh,41h,4bh,5bh
  14. IFDEF        FIND
  15.         db    4eh
  16. ENDIF
  17. NFunc        equ    $ - functions
  18. OK        db    ?
  19. func_table      dw      CreateFil       ;3ch - create handle
  20.         dw    OpenFil        ;3dh - open handle
  21.         dw    DeleteFil    ;41h - delete file
  22.         dw    Exec        ;4bh - load & execute
  23.         dw    CreateNew    ;5bh - create New File
  24. IFDEF        FIND
  25.         dw    FindFile    ;4eh - find file
  26. ENDIF
  27. MyPSP        dw    ?
  28. ;----------------- Program ---------------------
  29. IntHandler    proc    far
  30.         cmp    cs:[Off],1
  31.         je    Done
  32.         push    ax
  33.         push    bx
  34.         push    cx
  35.         push    dx
  36.         push    si
  37.         push    di
  38.         push    es
  39.         push    ds
  40.         push    bp
  41.         mov    bp,sp
  42. ParDs        equ    ss: word ptr [bp+ 2]
  43. ParEs        equ    ss: word ptr [bp+ 4]
  44. ParDx        equ    ss: word ptr [bp+10]
  45. ParCx        equ    ss: word ptr [bp+12]
  46. ParBx        equ    ss: word ptr [bp+14]
  47. ParAx        equ    ss: word ptr [bp+16]
  48. ParFlg        equ    ss: word ptr [bp+22]
  49.         cmp    ax,0c6c6h
  50.         jne    PolCont
  51.         mov    ax,ParFlg
  52.         or    ax,1
  53.         mov    ParFlg,ax
  54.         mov    ax,cs
  55.         add    sp,18
  56.         iret
  57. PolCont:    mov    ax,cs
  58.         mov    ds,ax
  59.         mov    ax,ParAx
  60.         mov    si,0
  61. next:        cmp    si,NFunc
  62.         je    cont
  63.         cmp    ah,functions[si]
  64.         je    subr
  65.         inc    si
  66.         jmp    next
  67. Subr:        shl    si,1
  68.                 call    func_table[si]
  69. cont:        mov    sp,bp
  70.         pop    bp
  71.         pop    ds
  72.         pop    es
  73.         pop    di
  74.         pop    si
  75.         pop    dx
  76.         pop    cx
  77.         pop    bx
  78.         pop    ax
  79. Done:        jmp    cs:[Old21]
  80. ;----------------------------------------------------------
  81. IntHandler    ENDP
  82. ;---------------------------------------------------------
  83. CreateFil:    call    cont1
  84.         db      'CreateFile  : ',0
  85. CreateNew:    call    Cont1
  86.         db      'CreateNew   : ',0
  87. DeleteFil:    call    cont1
  88.         db      'DeleteFile  : ',0
  89. IFDEF        FIND
  90. FindFile:    call    cont1
  91.         db      'FindFile    : ',0
  92. ENDIF
  93. ;---------------------------------------------------------
  94. OpenFil:    mov     ax,ParAX
  95.         cmp     al,0
  96.         jne     OpenFil1
  97.         call    cont1
  98.         db      'OpenFile-R  : ',0
  99. OpenFil1:    cmp     al,1
  100.         jnz     OpenFil2
  101.         call    cont1
  102.         db      'OpenFile-W  : ',0
  103. OpenFil2:    call    cont1
  104.         db      'OpenFile-R/W: ',0
  105. ;---------------------------------------------------------
  106. Exec:        call    Exec1
  107.         db      'Exec        : ',0
  108. Exec1:        pop     si
  109. ExLop:        lodsb
  110.         or      al,al
  111.         jz      ExCont
  112.         call    PutBuff
  113.         jmp     ExLop
  114. ExCont:        call    PutStr
  115.         mov     al,' '
  116.         call    PutBuff
  117.         call    PutParStr
  118.         call    PutCrLf
  119.         call    ApendTMP
  120.         retn
  121. ;---------------------------------------------------------
  122. Cont1:        pop     si
  123. CoLop:        lodsb
  124.         or      al,al
  125.         jz      CoCont
  126.         call    PutBuff
  127.         jmp     CoLop
  128. CoCont:        call    PutStr
  129.         call    PutCrLf
  130.         call    ApendTMP
  131.         retn
  132. ;---------------------------------------------------------
  133. PutParStr:    mov    es,parES
  134.         mov    bx,parBX
  135.         inc    bx
  136.         inc    bx
  137.         mov    si,es:[bx]
  138.         inc    bx
  139.         inc    bx
  140.         mov    ax,es:[bx]
  141.         mov    ds,ax
  142.         lodsb
  143.         cmp    al,0
  144.         jz    ParEnd
  145.         xor    ah,ah
  146.         mov    cx,ax
  147. Par1:        lodsb
  148.         cmp    al,0
  149.         jz    ParEnd
  150.         cmp    al,0dh
  151.         jz    ParEnd
  152.         call    PutBuff
  153.         loop    Par1
  154. ParEnd:        retn
  155. ;---------------------------------------------------------
  156. PutStr:        mov    ds,parDS
  157.         mov    si,parDX
  158. put1:        lodsb
  159.         cmp    al,0
  160.         jz    StrEnd
  161.         call    PutBuff
  162.         jmp    Put1
  163. StrEnd:        retn
  164. ;---------------------------------------------------------
  165. PutCrLf:    mov    al,0dh
  166.         call    PutBuff
  167.         mov    al,0ah
  168.         call    PutBuff
  169.         retn
  170. ;---------------------------------------------------------
  171. putbuff        proc    near
  172.         mov    bx,cs:[BuffPos]
  173.         inc    bx
  174.         cmp    bx,cs:[BuffSize]
  175.         je    rret
  176.         mov    cs:[BuffPos],bx
  177.         add    bx,offset ResEnd
  178.         dec    bx
  179.         mov    cs:[bx],al
  180. rret:        retn
  181. putbuff        endp
  182. ;-----------------------------------------------------------
  183. ApendTMP    proc    near
  184.         call    SetCrit
  185.         call    DosOK
  186.         jnz    stop
  187.         Call    OpenFile
  188.         JNB    handleOk
  189.         call    CreateFile
  190.         Call    OpenFile
  191.         jc    stop
  192. handleOk:    MOV    BX,AX        ;store file handle
  193.         MOV    AL,02h        ;eof move
  194.         MOV    CX,0        ;file offset
  195.         MOV    DX,0        ;lo(offset)
  196.         MOV    AH,42h        ;set file pointer
  197.         pushf
  198.         call    cs:[Old21]
  199. WriteTMP:    MOV    DX,offset ResEnd
  200.         mov    ax,cs
  201.         mov    ds,ax
  202.         mov    cx,buffpos    ;number of bytes
  203.         MOV    AH,40h        ;write to the file
  204.         pushf
  205.         call    cs:[Old21]
  206.         MOV    AH,3Eh        ;close file
  207.         pushf
  208.         call    cs:[Old21]
  209.         mov    buffpos,0
  210. stop:        call    RestoreCrit
  211.         retn
  212. ApendTMP    ENDP
  213. ;-----------------------------------------------------------
  214. OpenFile    proc    near
  215.         PUSH    CS
  216.         POP    DS
  217.         MOV    DX,offset path
  218.         MOV    AL,1        ;writing
  219.         MOV    AH,3Dh        ;open file handle
  220.         pushf
  221.         call    cs:[Old21]
  222.         ret
  223. OpenFile    endp
  224. ;----------------------------------------------------------
  225. CreateFile    proc    near
  226.         call    DosOK
  227.         jz    CreateCnt
  228.         stc
  229.         ret
  230. CreateCnt:    push    cs
  231.         pop    ds
  232.         MOV    DX,offset path
  233.         MOV    CX,0        ;file attribute
  234.         MOV    AH,5bh        ;create new file
  235.         pushf
  236.         call    cs:[Old21]
  237.         jnb    CreateCnt1
  238.         stc
  239.         ret
  240. CreateCnt1:    MOV    BX,AX        ;store file handle
  241.         MOV    AH,3Eh        ;close file handle
  242.         pushf
  243.         call    cs:[Old21]
  244.         clc
  245.         ret
  246. CreateFile    endp
  247. ;-----------------------------------------------------------
  248. DosOK        proc    near
  249.         PUSH    BX
  250.         PUSH    ES
  251.         LES     BX,cs:[status]
  252.         CMP     BYTE PTR es:[BX],0
  253.         POP     ES
  254.         POP     BX
  255.         RETN
  256. DosOK        ENDP
  257. ;----------------------------------------------------------
  258. SetCrit        proc    near
  259.         pushf
  260.         push    ax
  261.         push    dx
  262.         push    es
  263.         cli
  264.         mov    ax,0
  265.         mov    es,ax
  266.         mov    ax,Word Ptr es:[24h*4]
  267.         mov    Word Ptr cs:[Old24],ax
  268.         mov    ax,Word Ptr es:[24h*4+2]
  269.         mov    Word Ptr cs:[offset Old24 + 2],ax
  270.         mov    ax,cs
  271.         mov    Word Ptr es:[24h*4+2],ax
  272.         mov    ax,offset New24
  273.         mov    Word Ptr es:[24h*4],ax
  274.         mov    ax,3300h
  275.         pushf
  276.         call    cs:Old21    ;get ctrl-break state
  277.         mov    cs:[CtrlC],dl
  278.         sub    dl,dl
  279.         mov    al,1
  280.         pushf
  281.         call    cs:Old21    ;set ctrl-break off
  282.         pop    es
  283.         pop    dx
  284.         pop    ax
  285.         popf
  286.         ret
  287. SetCrit        endp
  288. ;----------------------------------------------------------
  289. RestoreCrit    proc    near
  290.         pushf
  291.         push    ax
  292.         push    dx
  293.         push    es
  294.         cli
  295.         mov    ax,0
  296.         mov    es,ax
  297.         mov    ax,Word Ptr cs:[Old24]
  298.         mov    Word Ptr es:[24h*4],ax
  299.         mov    ax,Word Ptr cs:[offset Old24 + 2]
  300.         mov    Word Ptr es:[24h*4+2],ax
  301.         mov    ax,3301h
  302.         mov    dl,cs:[CtrlC]
  303.         pushf
  304.         call    cs:[Old21]
  305.         pop    es
  306.         pop    dx
  307.         pop    ax
  308.         popf
  309.         ret
  310. RestoreCrit    endp
  311. ;----------------------------------------------------------
  312. Old24        dd    ?
  313. CtrlC        db    ?
  314. ;----------------------------------------------------------
  315. New24        proc    far    ;critical err.
  316.         mov    al,3    ;fail
  317.         mov    Byte Ptr CS:[Off],1
  318.         iret
  319. ;----------------------------------------------------------
  320. New24        endp
  321. ;----------------------------------------------------------
  322. ResEnd        label byte
  323. ;----------------------------------------------------------
  324. prompt        db    'Runtime saving of file actions.',13,10
  325.         db    'ver. 1.04',13,10
  326.         db    'Petr Horák, Praha 1992',13,10
  327.         db    'Usage: kgb [file] [/Options] ..',13,10
  328.         db    'Options:',0dh,0ah
  329.         db    '    /u unload',0dh,0ah
  330.         db    '    /dX drive X (A-Z)',0dh,0ah
  331.         db    '    /on (off)',0dh,0ah,'$'
  332. ;----------------------------------------------------------
  333. UnloadReq    db    0
  334. Default        db    1
  335. ;----------------------------------------------------------
  336. ReadCmdLine:    mov    ax,6200h
  337.         int    21h        ;get PSP address
  338.         mov    ds,bx
  339.         MOV    si,81h
  340.         MOV    cl,Byte Ptr ds:[80h]
  341.         xor    ch,ch
  342. ReadLoop:    call    SkipSpace
  343.         cmp    al,'/'
  344.         jnz    ReadCont
  345.         call    Switch
  346.         jmp    ReadLoop
  347. ReadCont:    cmp    Byte Ptr cs:[Default],0
  348.         je    ReadLoop    ;name
  349.         push    cx
  350.         dec    si
  351.         call    NameSet
  352.         inc    si
  353.         pop    cx
  354.         jmp    ReadLoop
  355. ;----------------------------------------------------------
  356. SkipSpace:    cmp    cx,0
  357.         jz    CmdEnd
  358.         dec    cx
  359.         lodsb            ;al <- ds:[si]
  360.         cmp    al,'/'
  361.         jz    SkipEnd
  362.         cmp    al,0dh
  363.         jz    CmdEnd
  364.         cmp    al,0
  365.         jz    CmdEnd
  366.         cmp    al,' '
  367.         jnz    SkipSpace
  368. SkipSpace1:    cmp    cx,0
  369.         jz    CmdEnd
  370.         dec    cx
  371.         lodsb            ;al <- ds:[si]
  372.         cmp    al,0dh
  373.         jz    CmdEnd
  374.         cmp    al,0
  375.         jz    CmdEnd
  376.         cmp    al,' '
  377.         jz    SkipSpace1
  378. SkipEnd:    ret
  379. ;----------------------------------------------------------
  380. CmdEnd:        pop    ax
  381.         ret
  382. ;----------------------------------------------------------
  383. Switch:        cmp    cx,0
  384.         jz    CmdEnd
  385.         lodsb
  386.         dec    cx
  387.         cmp    al,'u'
  388.         jnz    Read4
  389.         mov    cs:[UnloadReq],1
  390.         jmp    CmdEnd
  391. Read4:        cmp    al,'d'
  392.         jnz    Read5
  393.         cmp    cs:[Default],0
  394.         jz    Read5
  395.         cal